package cool.webstudy.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cool.webstudy.admin.constant.enums.DelFlagEnum;
import cool.webstudy.admin.constant.enums.rescode.CompetitionTeamResCodeEnum;
import cool.webstudy.admin.constant.enums.rescode.TeamUserResCodeEnum;
import cool.webstudy.admin.constant.enums.rescode.UserResCodeEnum;
import cool.webstudy.admin.exception.BusinessException;
import cool.webstudy.admin.mapper.competition.team.CompetitionTeamMapper;
import cool.webstudy.admin.model.dto.competition.team.*;
import cool.webstudy.admin.model.dto.team.TeamDetailInfoDTO;
import cool.webstudy.admin.model.dto.user.UserDetailInfoDTO;
import cool.webstudy.admin.model.po.competition.team.CompetitionTeamPO;
import cool.webstudy.admin.model.po.team.user.TeamUserPO;
import cool.webstudy.admin.model.vo.competition.team.PaginationQueryCompetitionTeamInfoListVO;
import cool.webstudy.admin.model.vo.competition.team.QueryCompTeamDetailWithLoginInfoVO;
import cool.webstudy.admin.model.vo.competition.team.QueryCompTeamHostNetInfoVO;
import cool.webstudy.admin.model.vo.competition.team.QueryOwnCompTeamHostWithLoginInfoVO;
import cool.webstudy.admin.model.vo.team.user.QueryTeamUserDetailInfoVO;
import cool.webstudy.admin.service.CompetitionTeamService;
import cool.webstudy.admin.service.TeamService;
import cool.webstudy.admin.service.TeamUserService;
import cool.webstudy.admin.utils.UserDetailUtil;
import cool.webstudy.common.utils.UUIDUtil;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.binding.MapperMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author 莫振双
 * @date 2025/1/23 12:12
 * @description: 赛事与队伍关联关系服务实现类
 */
@Service
public class CompetitionTeamServiceImpl extends ServiceImpl<CompetitionTeamMapper, CompetitionTeamPO> implements CompetitionTeamService {
    @Autowired
    private CompetitionTeamMapper competitionTeamMapper;
    @Autowired
    private TeamService teamService;
    @Autowired
    private TeamUserService teamUserService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean createCompetitionTeam(CreateCompetitionTeamDTO dto) {
        UserDetailInfoDTO userDetailInfo = UserDetailUtil.getUserDetailInfo();
        CompetitionTeamPO competitionTeamPO = new CompetitionTeamPO();
        competitionTeamPO.setCompUnCode(dto.getCompUnCode());
        competitionTeamPO.setTeamUnCode(dto.getTeamUnCode());
        competitionTeamPO.setContainerId(dto.getContainerId());
        competitionTeamPO.setUnCode(UUIDUtil.getUUID());
        competitionTeamPO.setCreateBy(userDetailInfo.getAccount());
        competitionTeamPO.setCreateTime(new Date());
        competitionTeamPO.setUpdateBy(userDetailInfo.getAccount());
        competitionTeamPO.setUpdateTime(new Date());
        competitionTeamPO.setDelFlag(DelFlagEnum.NOT_DEL_FLAG.getFlag());
        try {
            this.save(competitionTeamPO);
        } catch (Exception e) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_CREATE);
        }
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean batchCreateCompetitionTeam(List<CreateCompetitionTeamDTO> dtoList) {
        if (dtoList == null || dtoList.isEmpty()) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_CREATE);
        }
        UserDetailInfoDTO userDetailInfo = UserDetailUtil.getUserDetailInfo();
        List<CompetitionTeamPO> competitionTeamPOList = new ArrayList<>();
        for (CreateCompetitionTeamDTO dto : dtoList) {
            CompetitionTeamPO competitionTeamPO = new CompetitionTeamPO();
            competitionTeamPO.setCompUnCode(dto.getCompUnCode());
            competitionTeamPO.setTeamUnCode(dto.getTeamUnCode());
            competitionTeamPO.setContainerId(dto.getContainerId());
            competitionTeamPO.setCurrentScore(dto.getCurrentScore());
            competitionTeamPO.setTeamNetAddress(dto.getTeamNetAddress());
            competitionTeamPO.setTeamNetPort(dto.getTeamNetPort());
            competitionTeamPO.setUnCode(UUIDUtil.getUUID());
            competitionTeamPO.setCreateBy(userDetailInfo.getAccount());
            competitionTeamPO.setCreateTime(new Date());
            competitionTeamPO.setUpdateBy(userDetailInfo.getAccount());
            competitionTeamPO.setUpdateTime(new Date());
            competitionTeamPO.setDelFlag(DelFlagEnum.NOT_DEL_FLAG.getFlag());
            competitionTeamPOList.add(competitionTeamPO);
        }
        try {
            this.saveBatch(competitionTeamPOList);
        } catch (Exception e) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_CREATE);
        }
        return true;
    }

    @Override
    public List<QueryCompTeamDetailInfoDTO> queryCompTeamDetailInfoList(String competitionUnCode) {
        if (StringUtils.isBlank(competitionUnCode)) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_QUERY_PARAM_MISS);
        }
        LambdaQueryWrapper<CompetitionTeamPO> queryWrapper = new LambdaQueryWrapper<>();
        try {
            List<CompetitionTeamPO> competitionTeamPOList = competitionTeamMapper.selectList(queryWrapper);
            if (competitionTeamPOList == null || competitionTeamPOList.isEmpty()) {
                return List.of();
            }
            List<QueryCompTeamDetailInfoDTO> queryCompTeamDetailInfoDTOList = new ArrayList<>();
            for (CompetitionTeamPO competitionTeamPO : competitionTeamPOList) {
                QueryCompTeamDetailInfoDTO queryCompTeamDetailInfoDTO = new QueryCompTeamDetailInfoDTO();
                queryCompTeamDetailInfoDTO.setUnCode(competitionTeamPO.getUnCode());
                queryCompTeamDetailInfoDTO.setCompUnCode(competitionTeamPO.getCompUnCode());
                queryCompTeamDetailInfoDTO.setTeamUnCode(competitionTeamPO.getTeamUnCode());
                queryCompTeamDetailInfoDTO.setContainerId(competitionTeamPO.getContainerId());
                queryCompTeamDetailInfoDTO.setTeamNetAddress(competitionTeamPO.getTeamNetAddress());
                queryCompTeamDetailInfoDTO.setCurrentScore(competitionTeamPO.getCurrentScore());
                queryCompTeamDetailInfoDTOList.add(queryCompTeamDetailInfoDTO);
            }
            return queryCompTeamDetailInfoDTOList;
        } catch (Exception e) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_QUERY);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void batchUpdateCompetitionTeamFlag(List<UpdateCompetitionTeamFlagDTO> dtoList) {
        if (dtoList == null || dtoList.isEmpty()) {
            return;
        }
        List<CompetitionTeamPO> competitionTeamPOList = new ArrayList<>();
        for (UpdateCompetitionTeamFlagDTO dto : dtoList) {
            CompetitionTeamPO competitionTeamPO = new CompetitionTeamPO();
            competitionTeamPO.setDynamicFlagValue(dto.getFlag());
            competitionTeamPO.setUnCode(dto.getUnCode());
            competitionTeamPOList.add(competitionTeamPO);
        }
        try {
            updateBatchById(competitionTeamPOList);
        } catch (Exception e) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_BATCH_UPDATE_FLAG);
        }
    }

    @Override
    public Boolean isExistRecord(String competitionUnCode, String[] teamUnCodeArr) {
        if (StringUtils.isBlank(competitionUnCode) || ArrayUtils.isEmpty(teamUnCodeArr)) {
            return false;
        }
        LambdaQueryWrapper<CompetitionTeamPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CompetitionTeamPO::getCompUnCode, competitionUnCode)
                .in(CompetitionTeamPO::getTeamUnCode, teamUnCodeArr);
        try {
            List<CompetitionTeamPO> competitionTeamPOList = competitionTeamMapper.selectList(queryWrapper);
            if (competitionTeamPOList == null || competitionTeamPOList.isEmpty()) {
                return false;
            }
            return true;
        } catch (Exception e) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_QUERY);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void batchUpdateCompetitionTeamLoginInfo(List<UpdateCompTeamLoginInfoDTO> dtoList) {
        if (dtoList == null || dtoList.isEmpty()) {
            return;
        }
        List<CompetitionTeamPO> competitionTeamPOList = new ArrayList<>();
        for (UpdateCompTeamLoginInfoDTO dto : dtoList) {
            CompetitionTeamPO competitionTeamPO = new CompetitionTeamPO();
            competitionTeamPO.setCompUnCode(dto.getCompetitionUnCode());
            competitionTeamPO.setTeamUnCode(dto.getTeamUnCode());
            competitionTeamPO.setContainerId(dto.getContainerId());
            competitionTeamPO.setTeamAccount(dto.getTeamAccount());
            competitionTeamPO.setTeamPassword(dto.getTeamPassword());
            competitionTeamPO.setUpdateTime(new Date());
            competitionTeamPOList.add(competitionTeamPO);
        }
        try {
            //批量更新
            updateBatchByQueryWrapper(competitionTeamPOList, po -> {
                LambdaQueryWrapper<CompetitionTeamPO> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(CompetitionTeamPO::getCompUnCode, po.getCompUnCode())
                        .eq(CompetitionTeamPO::getContainerId, po.getContainerId());
                return wrapper;
            });
        } catch (Exception e) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_BATCH_UPDATE_LOGIN_INFO);
        }
    }
    /**
     * @param entityList 实体列表
     * @param queryWrapperFunction
     * @return boolean
     * @description: 根据条件批量更新
     */
    private boolean updateBatchByQueryWrapper(Collection<CompetitionTeamPO> entityList, Function<CompetitionTeamPO, LambdaQueryWrapper> queryWrapperFunction) {
        String sqlStatement = this.getSqlStatement(SqlMethod.UPDATE);
        return this.executeBatch(entityList, DEFAULT_BATCH_SIZE, (sqlSession, entity) -> {
            MapperMethod.ParamMap param = new MapperMethod.ParamMap();
            param.put(Constants.ENTITY, entity);
            param.put(Constants.WRAPPER, queryWrapperFunction.apply(entity));
            sqlSession.update(sqlStatement, param);
        });
    }

    @Override
    public Page<PaginationQueryCompetitionTeamInfoListVO> paginationQueryCompetitionTeamInfoList(PaginationQueryCompetitionTeamInfoListDTO dto) {
        Page<PaginationQueryCompetitionTeamInfoListVO> paginationQueryCompetitionTeamInfoVOPage = new Page<>();
        Page<CompetitionTeamPO> page = new Page<>(dto.getCurrent(), dto.getPageSize());
        LambdaQueryWrapper<CompetitionTeamPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CompetitionTeamPO::getCompUnCode, dto.getCompetitionUnCode());
        try {
            Page<CompetitionTeamPO> competitionTeamPOPage = competitionTeamMapper.selectPage(page, queryWrapper);
            if (competitionTeamPOPage == null || competitionTeamPOPage.getRecords() == null || competitionTeamPOPage.getRecords().isEmpty()) {
                return paginationQueryCompetitionTeamInfoVOPage;
            }
            //获取队伍业务主键与队伍名称的map
            Map<String, String> teamRoughInfoMap = teamService.queryTeamRoughInfoMap();
            paginationQueryCompetitionTeamInfoVOPage.setTotal(competitionTeamPOPage.getTotal());
            paginationQueryCompetitionTeamInfoVOPage.setPages(competitionTeamPOPage.getPages());
            //封装数据
            paginationQueryCompetitionTeamInfoVOPage.setRecords(competitionTeamPOPage.getRecords().stream().map(competitionTeamPO -> {
                PaginationQueryCompetitionTeamInfoListVO paginationQueryCompetitionTeamInfoListVO = new PaginationQueryCompetitionTeamInfoListVO();
                paginationQueryCompetitionTeamInfoListVO.setUnCode(competitionTeamPO.getUnCode());
                paginationQueryCompetitionTeamInfoListVO.setCompetitionUnCode(competitionTeamPO.getCompUnCode());
                paginationQueryCompetitionTeamInfoListVO.setTeamUnCode(competitionTeamPO.getTeamUnCode());
                //翻译队伍名称
                paginationQueryCompetitionTeamInfoListVO.setTeamName(teamRoughInfoMap.get(competitionTeamPO.getTeamUnCode()));
                paginationQueryCompetitionTeamInfoListVO.setContainerId(competitionTeamPO.getContainerId());
                paginationQueryCompetitionTeamInfoListVO.setDynamicFlagValue(competitionTeamPO.getDynamicFlagValue());
                paginationQueryCompetitionTeamInfoListVO.setCreateBy(competitionTeamPO.getCreateBy());
                paginationQueryCompetitionTeamInfoListVO.setCreateTime(competitionTeamPO.getCreateTime());
                paginationQueryCompetitionTeamInfoListVO.setUpdateBy(competitionTeamPO.getUpdateBy());
                paginationQueryCompetitionTeamInfoListVO.setUpdateTime(competitionTeamPO.getUpdateTime());
                return paginationQueryCompetitionTeamInfoListVO;
            }).collect(Collectors.toList()));
            return paginationQueryCompetitionTeamInfoVOPage;
        } catch (Exception e) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_QUERY);
        }
    }

    @Override
    public QueryCompTeamDetailWithLoginInfoVO queryCompTeamDetailWithLoginInfo(String unCode) {
        if (StringUtils.isBlank(unCode)) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_QUERY_PARAM_MISS);
        }
        LambdaQueryWrapper<CompetitionTeamPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CompetitionTeamPO::getUnCode, unCode);
        try {
            CompetitionTeamPO competitionTeamPO = competitionTeamMapper.selectOne(queryWrapper);
            if (Objects.isNull(competitionTeamPO)) {
                throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_RECORD_NOT_EXIST);
            }
            //查询需要翻译的信息
            TeamDetailInfoDTO teamDetailInfoDTO = teamService.queryTeamDetailInfoDTO(competitionTeamPO.getTeamUnCode());

            QueryCompTeamDetailWithLoginInfoVO queryCompTeamDetailWithLoginInfoVO = new QueryCompTeamDetailWithLoginInfoVO();
            queryCompTeamDetailWithLoginInfoVO.setUnCode(competitionTeamPO.getUnCode());
            queryCompTeamDetailWithLoginInfoVO.setCompetitionUnCode(competitionTeamPO.getCompUnCode());
            queryCompTeamDetailWithLoginInfoVO.setTeamUnCode(competitionTeamPO.getTeamUnCode());
            queryCompTeamDetailWithLoginInfoVO.setTeamName(teamDetailInfoDTO.getName());
            queryCompTeamDetailWithLoginInfoVO.setContainerId(competitionTeamPO.getContainerId());
            queryCompTeamDetailWithLoginInfoVO.setDynamicFlagValue(competitionTeamPO.getDynamicFlagValue());
            queryCompTeamDetailWithLoginInfoVO.setTeamNetAddress(competitionTeamPO.getTeamNetAddress());
            queryCompTeamDetailWithLoginInfoVO.setTeamNetPort(competitionTeamPO.getTeamNetPort());
            queryCompTeamDetailWithLoginInfoVO.setTeamAccount(competitionTeamPO.getTeamAccount());
            queryCompTeamDetailWithLoginInfoVO.setTeamPassword(competitionTeamPO.getTeamPassword());
            queryCompTeamDetailWithLoginInfoVO.setCurrentTeamScore(competitionTeamPO.getCurrentScore());
            return queryCompTeamDetailWithLoginInfoVO;
        } catch (Exception e) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_QUERY);
        }
    }

    @Override
    public QueryOwnCompTeamHostWithLoginInfoVO queryOwnCompTeamDetailInfoWithLoginInfo() {
        //查询当前登录用户
        UserDetailInfoDTO userDetailInfo = UserDetailUtil.getUserDetailInfo();
        if (Objects.isNull(userDetailInfo)){
            return null;
        }
        if("system".equals(userDetailInfo.getAccount())){
            throw new BusinessException(UserResCodeEnum.RC_ERROR_NOT_LOGIN);
        }
        //查询当前登录用户的队伍信息
        QueryTeamUserDetailInfoVO queryTeamUserDetailInfoVO = teamUserService.queryTeamUserDetailInfoByUserUnCode(userDetailInfo.getUnCode());
        if (Objects.isNull(queryTeamUserDetailInfoVO)){
            throw new BusinessException(TeamUserResCodeEnum.RC_ERROR_NOT_IN_TEAM);
        }
        //查询队伍主机信息
        LambdaQueryWrapper<CompetitionTeamPO> compTeamQueryWrapper = new LambdaQueryWrapper<>();
        compTeamQueryWrapper.eq(CompetitionTeamPO::getTeamUnCode,queryTeamUserDetailInfoVO.getTeamUnCode());
        try {
            CompetitionTeamPO competitionTeamPO = competitionTeamMapper.selectOne(compTeamQueryWrapper);
            if (Objects.isNull(competitionTeamPO)){
                throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_TEAM_NOT_IN_COMPETITION);
            }
            QueryOwnCompTeamHostWithLoginInfoVO queryOwnCompTeamHostWithLoginInfoVO = new QueryOwnCompTeamHostWithLoginInfoVO();
            queryOwnCompTeamHostWithLoginInfoVO.setUnCode(competitionTeamPO.getUnCode());
            queryOwnCompTeamHostWithLoginInfoVO.setCompetitionUnCode(competitionTeamPO.getCompUnCode());
            queryOwnCompTeamHostWithLoginInfoVO.setTeamNetAddress(competitionTeamPO.getTeamNetAddress());
            queryOwnCompTeamHostWithLoginInfoVO.setTeamNetPort(competitionTeamPO.getTeamNetPort());
            queryOwnCompTeamHostWithLoginInfoVO.setTeamAccount(competitionTeamPO.getTeamAccount());
            queryOwnCompTeamHostWithLoginInfoVO.setTeamPassword(competitionTeamPO.getTeamPassword());
            return queryOwnCompTeamHostWithLoginInfoVO;
        } catch (Exception e) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_QUERY);
        }
    }

    @Override
    public QueryCompTeamDetailInfoDTO queryCompTeamDetailInfoByFlag(String flag) {
        if (StringUtils.isBlank(flag)){
            return null;
        }
        LambdaQueryWrapper<CompetitionTeamPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CompetitionTeamPO::getDynamicFlagValue,flag);
        try {
            CompetitionTeamPO competitionTeamPO = competitionTeamMapper.selectOne(queryWrapper);
            if (Objects.isNull(competitionTeamPO)){
                return null;
            }
            QueryCompTeamDetailInfoDTO queryCompTeamDetailInfoDTO = new QueryCompTeamDetailInfoDTO();
            queryCompTeamDetailInfoDTO.setUnCode(competitionTeamPO.getUnCode());
            queryCompTeamDetailInfoDTO.setCompUnCode(competitionTeamPO.getCompUnCode());
            queryCompTeamDetailInfoDTO.setTeamUnCode(competitionTeamPO.getTeamUnCode());
            return queryCompTeamDetailInfoDTO;
        }catch (Exception e){
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_QUERY);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer updateCompTeamScore(String compUnCode,String teamUnCode, Integer score, Boolean isAdd) {
        if (score < 0){
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_SCORE_INVALID);
        }
        if (StringUtils.isBlank(compUnCode) || StringUtils.isBlank(teamUnCode)){
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_QUERY_PARAM_MISS);
        }
        LambdaQueryWrapper<CompetitionTeamPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CompetitionTeamPO::getCompUnCode,compUnCode)
                .eq(CompetitionTeamPO::getTeamUnCode,teamUnCode);
        CompetitionTeamPO competitionTeamPO = competitionTeamMapper.selectOne(queryWrapper);
        if (Objects.isNull(competitionTeamPO)){
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_RECORD_NOT_EXIST);
        }
        try {
            if (isAdd){
                competitionTeamPO.setCurrentScore(competitionTeamPO.getCurrentScore() + score);
            }else {
                competitionTeamPO.setCurrentScore(competitionTeamPO.getCurrentScore() - score);
            }
            //更新当前队伍分数
            LambdaUpdateWrapper<CompetitionTeamPO> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(CompetitionTeamPO::getUnCode,competitionTeamPO.getUnCode())
                    .set(CompetitionTeamPO::getCurrentScore,competitionTeamPO.getCurrentScore());
            competitionTeamMapper.update(null,updateWrapper);
            return competitionTeamPO.getCurrentScore();
        }catch (Exception e){
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_SCORE_COMPUTE_FAIL);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void batchUpdateCompetitionTeamScore(List<UpdateCompetitionTeamScoreDTO> dtoList) {
        if (Objects.isNull(dtoList) || dtoList.isEmpty()){
            return;
        }
        List<CompetitionTeamPO> competitionTeamPOList = new ArrayList<>();
        for (UpdateCompetitionTeamScoreDTO dto : dtoList) {
            CompetitionTeamPO competitionTeamPO = new CompetitionTeamPO();
            competitionTeamPO.setCompUnCode(dto.getCompUnCode());
            competitionTeamPO.setTeamUnCode(dto.getTeamUnCode());
            competitionTeamPO.setCurrentScore(dto.getCurrentScore());
            competitionTeamPO.setUpdateTime(new Date());
            competitionTeamPOList.add(competitionTeamPO);
        }
        try {
            //批量更新
            updateBatchByQueryWrapper(competitionTeamPOList, po -> {
                LambdaQueryWrapper<CompetitionTeamPO> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(CompetitionTeamPO::getCompUnCode, po.getCompUnCode())
                        .eq(CompetitionTeamPO::getTeamUnCode, po.getTeamUnCode());
                return wrapper;
            });
        } catch (Exception e) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_BATCH_UPDATE_SCORE_FAIL);
        }
    }

    @Override
    public List<QueryCompTeamHostNetInfoVO> queryCompTeamHostNetInfoList(String competitionUnCode) {
        if (StringUtils.isBlank(competitionUnCode)){
            return List.of();
        }
        LambdaQueryWrapper<CompetitionTeamPO> queryWrapper = new LambdaQueryWrapper<>();
        try {
            List<CompetitionTeamPO> competitionTeamPOList = competitionTeamMapper.selectList(queryWrapper);
            if (!competitionTeamPOList.isEmpty()){
                //查询队伍信息map
                Map<String,String> teamRoughInfoMap = teamService.queryTeamRoughInfoMap();
                List<QueryCompTeamHostNetInfoVO> queryCompTeamHostNetInfoVOList = new ArrayList<>();
                competitionTeamPOList.forEach(competitionTeamPO -> {
                    QueryCompTeamHostNetInfoVO queryCompTeamHostNetInfoVO = new QueryCompTeamHostNetInfoVO();
                    queryCompTeamHostNetInfoVO.setUnCode(competitionTeamPO.getUnCode());
                    queryCompTeamHostNetInfoVO.setCompetitionUnCode(competitionTeamPO.getCompUnCode());
                    queryCompTeamHostNetInfoVO.setTeamUnCode(competitionTeamPO.getTeamUnCode());
                    queryCompTeamHostNetInfoVO.setTeamName(teamRoughInfoMap.get(competitionTeamPO.getTeamUnCode()));
                    queryCompTeamHostNetInfoVO.setTeamNetAddress(competitionTeamPO.getTeamNetAddress());
                    queryCompTeamHostNetInfoVO.setTeamNetPort(competitionTeamPO.getTeamNetPort());
                    queryCompTeamHostNetInfoVOList.add(queryCompTeamHostNetInfoVO);
                });
                return queryCompTeamHostNetInfoVOList;
            }
            return List.of();
        } catch (Exception e) {
            throw new BusinessException(CompetitionTeamResCodeEnum.RC_ERROR_QUERY);
        }
    }
}
